package com.yidu.menuProject.action;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yidu.menuProject.action.vo.EhyRoleVo;
import com.yidu.menuProject.common.Tools;
import com.yidu.menuProject.model.EhyRoleModel;
import com.yidu.menuProject.service.EhyRoleService;

@Controller
@RequestMapping("/roleAction")
public class EhyRoleAction {
	@Resource 
	private EhyRoleService ehyRoleService;
	@Transactional(readOnly=false)
	
	
	
	/**
	 * 查询所有用户
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/showList")
	public  Map<String, Object>  showList(EhyRoleVo vo,int page,int limit) {
		EhyRoleVo role = new EhyRoleVo();
		
		vo.setNowpage(page);
		vo.setRows(limit);
		List<EhyRoleModel> list = ehyRoleService.selectAll(vo);
		Integer count = ehyRoleService.selectCount(role);
		
		Map<String, Object> map=new HashMap<>();
		map.put("code", 0);
		map.put("msg", null);
		map.put("count", count);
		map.put("data", list);
		
		
		return map;
		
	}
	@ResponseBody
	@RequestMapping("/showRole")
	public  List<EhyRoleModel>  showRole(EhyRoleVo vo) {
		List<EhyRoleModel> list = ehyRoleService.selectRole(vo);
		return list;
		
	}
	
	@ResponseBody
	@RequestMapping("/selectRole")
	public  List<EhyRoleModel>  selectRole(String manId) {
		List<EhyRoleModel> list = ehyRoleService.selectManagerRole(manId);
		return list;
		
	}
	
	
	
	/**
	 * 增加或修改
	 * @throws IOException 
	 */
	
	@RequestMapping("/updateRole")
	public String updateModule(EhyRoleVo vo) {
		ehyRoleService.updateByPrimaryKeySelective(vo);
		vo = new EhyRoleVo();
		return "redirect:/pages/pages_xc/RoleList.html";
		
		
	}
	
	
	
	@RequestMapping("/addRole")
	public String addModule(EhyRoleVo vo){
		vo.setRoleId(Tools.getStringRandom(10));
		vo.setIsva(3);
		ehyRoleService.insertSelective(vo);
		vo = new EhyRoleVo();
		return "redirect:/pages/pages_xc/RoleList.html";
		
	}
	/**
	 * 删除用户
	 * @return
	 * @throws IOException 
	 */
	@ResponseBody
	@RequestMapping("/delete")
	public String delete(String roleId){
		 System.out.println("==========================");
		 ehyRoleService.deleteByPrimaryKey(roleId);
		
		return "pages_xc/RoleList" ;
	}
	
	/**
	 * 修改根据id上传赋值
	 * @return
	 */
	@RequestMapping("/updateAss")
	public String updateAss(EhyRoleVo vo) {
		vo = ehyRoleService.findById(vo.getRoleId());
		
		return "update";
	}
	
	
	
	
}

